import random
import string
from user import User
from bank import Bank
from address import Address


# 界面程序
def main():
    bank = Bank("中国工商")
    while True:
        print("\n银行业务选择菜单：")
        print("1. 添加用户")
        print("2. 存钱")
        print("3. 取钱")
        print("4. 转账")
        print("5. 查询账户")
        print("6. 退出")
        choice = input("请选择业务（1-6）：")

        if choice == '1':
            account = ''.join(random.choices(string.digits, k=8))
            print("您的账号为：" + account)
            name = input("请输入姓名：")
            password = input("请输入密码（6位数字）：")
            country = input("请输入国家：")
            province = input("请输入省份：")
            street = input("请输入街道：")
            house_number = input("请输入门牌号：")
            balance = int(input("请输入存款余额："))
            address = Address(country, province, street, house_number)
            user = User(account, name, password, address, balance, bank.bank_name)
            result = bank.add_user(user)
            if result == 1:
                print("用户添加成功。")
            elif result == 2:
                print("用户已存在。")
            elif result == 3:
                print("用户库已满。")
        elif choice == '2':
            account = input("请输入账号：")
            amount = float(input("请输入存款金额："))
            if bank.deposit(account, amount):
                print("存款成功。")
            else:
                print("存款失败。")
        elif choice == '3':
            account = input("请输入账号：")
            password = input("请输入密码：")
            amount = float(input("请输入取款金额："))
            result = bank.withdraw(account, password, amount)
            if result == 0:
                print("取款成功。")
            elif result == 1:
                print("账号不存在。")
            elif result == 2:
                print("密码不对。")
            elif result == 3:
                print("钱不够。")
        elif choice == '4':
            from_account = input("请输入转出账号：")
            to_account = input("请输入转入账号：")
            password = input("请输入密码：")
            amount = float(input("请输入转账金额："))
            result = bank.transfer(from_account, to_account, password, amount)
            if result == 0:
                print("转账成功。")
            elif result == 1:
                print("账号不对。")
            elif result == 2:
                print("密码不对。")
            elif result == 3:
                print("钱不够。")
        elif choice == '5':
            account = input("请输入账号：")
            password = input("请输入密码：")
            bank.query_account(account, password)
        elif choice == '6':
            print("退出系统。")
            break
        else:
            print("无效选项，请重新选择。")

if __name__ == "__main__":
    main()